//
//  MenuTableViewCell.m
//  PopMenuTableView
//
//  Created by 孔繁武 on 16/8/2.
//  Copyright © 2016年 KongPro. All rights reserved.
//

#import "MenuTableViewCell.h"
#import "UIColor+additions.h"



@implementation MenuTableViewCell {
    UIView *_lineView;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setUpUI];
    }
    return self;
}

- (void)setUpUI{
    UIView *lineView = [[UIView alloc] init];
    lineView.backgroundColor = [UIColor lightGrayColor];
    _lineView = lineView;
    //红点标记
    self.redMark = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 10 * [UIScreen zj_screenWScale], 10 * [UIScreen zj_screenWScale])];
    self.redMark.backgroundColor = [UIColor themeColor];
    self.redMark.layer.masksToBounds = YES;
    
    [self addSubview:self.redMark];
    [self addSubview:lineView];
    self.backgroundColor = [UIColor clearColor];
    self.textLabel.font = [UIFont systemFontOfSize:14];
    self.textLabel.textColor = [UIColor textBlackColor];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    _lineView.frame = CGRectMake(4, self.bounds.size.height - 1, self.bounds.size.width - 8, 0.5);
    self.imageView.frame = CGRectMake(10 * [UIScreen zj_screenWScale], 10 * [UIScreen zj_screenHScale], self.height - 20 * [UIScreen zj_screenHScale], self.height - 20 * [UIScreen zj_screenHScale]);
    self.textLabel.frame = CGRectMake(self.imageView.right + 10 * [UIScreen zj_screenWScale], 0,[NSString zj_sizeOfString:self.textLabel.text font:self.textLabel.font width:[UIScreen zj_screenWith]].width , [NSString heightWithTextFont:self.textLabel.font]);
    
    self.textLabel.y = (self.height - self.textLabel.height) / 2;
    
    self.redMark.center = CGPointMake(self.textLabel.right + 10 * [UIScreen zj_screenWScale], self.textLabel.y);
    self.redMark.layer.cornerRadius = self.redMark.height / 2.0;
    
}

- (void)setMenuModel:(MenuModel *)menuModel{
    _menuModel = menuModel;
    self.imageView.image = [UIImage imageNamed:menuModel.imageName];
    self.textLabel.text = menuModel.itemName;
   
}

- (void)setUnderLineHidden:(BOOL)underLineHidden{
    _underLineHidden = underLineHidden;
    _lineView.hidden = _underLineHidden;
}

@end
